Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[local_auth] Fix iOS crash when no localizedReason #3780

Merged
merged 7 commits into from
Apr 9, 2021

Conversation

enricobenedos
Copy link
Contributor

@enricobenedos enricobenedos commented Apr 2, 2021

If you fill localizedReason with an empty string the app crash without any exception or log on iOS simulator. I've added an assertion and a related test in order to notify developer that the field cannot be null but also cannot be an empty string.

This PR should fix #77794.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@google-cla
Copy link

google-cla bot commented Apr 2, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@enricobenedos
Copy link
Contributor Author

@googlebot I fixed it.

@@ -101,6 +101,8 @@ class LocalAuthentication {
bool biometricOnly = false,
}) async {
assert(localizedReason != null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this plugin has migrated to null safety, this line is actually not necessary anymore. Feel free to remove it while you are here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -101,6 +101,8 @@ class LocalAuthentication {
bool biometricOnly = false,
}) async {
assert(localizedReason != null);
assert(localizedReason.isNotEmpty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior on android if this is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Android 11 (simulator) there are no problems if the localizedReason is empty. Is it a good idea to add the assert only on iOS case using Platform.isIOS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to add the assert only on iOS case using Platform.isIOS?

Yes. If android can handle null, especially if null and empty string means different things on android, we should allow null on android. Do you know if there are difference between null and empty string on android?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again. I think you are right, we really shouldn't allow empty strings or null on android either. So the change looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enricobenedos Let's make sure to mention the localizedReason must not be an empty String in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @cyanglaz, sorry for the delay but I'm a little bit busy. I'm happy that you check that is it a good idea to also not give the possibility to input an empty string on Android. I will update the docs soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks, once you update the doc we will land this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the authenticate method documentation.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost ready! Just some nits :)

packages/local_auth/CHANGELOG.md Outdated Show resolved Hide resolved
packages/local_auth/lib/local_auth.dart Outdated Show resolved Hide resolved
@enricobenedos
Copy link
Contributor Author

Thank you @cyanglaz, I've applied your suggestions 😃

@cyanglaz cyanglaz added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 9, 2021
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! LGTM

@fluttergithubbot fluttergithubbot merged commit 1dbc262 into flutter:master Apr 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 9, 2021
bhaveshptl pushed a commit to bhaveshptl/plugins that referenced this pull request Apr 23, 2021
* master: (397 commits)
  [in_app_purchase] Implementation of platform interface (flutter#3781)
  [google_sign_in] Add todo WRT correctly setting X-Goog-AuthUser header (flutter#3819)
  [tools] fix version check command not working for new packages (flutter#3818)
  [camera] android-rework part 1: Base classes to support Android Camera features (flutter#3795)
  fix MD (flutter#3815)
  Path provider windows crash fix (flutter#3814)
  [local_auth] docs update (flutter#3103)
  Update PULL_REQUEST_TEMPLATE.md (flutter#3801)
  [quick_actions] handle cold start on iOS correctly (flutter#3811)
  Replace path_provider_linux widget tests with simple unit tests (flutter#3812)
  [sensors] format dart code based on the new dart formatter (flutter#3809)
  [google_sign_in] Fix "pick account" on iOS (flutter#3805)
  [image_picker_platform_interface] Added pickMultiImage (flutter#3782)
  [in_app_purchase] Added currency code and numerical price to product detail model. (flutter#3794)
  [local_auth] Fix iOS crash when no localizedReason (flutter#3780)
  Fix and update version checks (flutter#3792)
  [in_app_purchase] Configured example app to use StoreKit Testing on iOS 14 (flutter#3772)
  [local_auth] Unnecessary reassignment in example removed (flutter#2983)
  [flutter_webview] Fix `allowsInlineMediaPlayback` ignored on iOS (flutter#3791)
  Switch script/tools over to the new analysis options (flutter#3777)
  ...
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: local_auth waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[local_auth] authenticate() crashes the app on iOS when localizedReason is empty
3 participants